// pages/me/balance/withdrawal/index.js
import utils from '../../../../utils/utils';
import Dialog from "../../../../dist/dialog/dialog";
Page({
  /**
   * 页面的初始数据
   */
  initFlag: false,
  data: {
    pean:'',
    userInfo:{
      common:{
        card_blance:0
      }
    }
  },
  onHide() {
    this.initFlag = true;
  },
  onShow() {
    if (this.initFlag === true) {
      this.initFlag = false;
      let self = this;
      self.getUserInfo(function (userInfo) {
        self.setData({
          userInfo:userInfo
        });
      },false,true);
    }
  },
  initPage:function () {
    let self = this;
    self.getUserInfo(function (userInfo) {
      self.setData({
        userInfo:userInfo
      });
    },false,true);
  },
  changeInput:function(e){
    let userPea  = utils.formatMoney(this.data.userInfo.common.card_blance, 2);
    let inputPea = utils.fixFloat(e.detail.value);
    if(inputPea >= userPea){
      inputPea = userPea;
    }
    if(inputPea === 0){
      inputPea = '';
    }
    this.setData({
      pean:inputPea
    });
  },
  toAll:function(){
    this.setData({
      pean:utils.fixFloat(this.data.userInfo.common.card_blance / 100)
    });
  },
  toWithDraw:function () {
    let self = this;
    if(this.data.pean <= 0){
      utils.msg('请输入要提现的金额！');
      return false;
    }
    Dialog.confirm({
      message: '确定提现' + this.data.pean + '元吗？',
      confirmButtonText: "立即提现",
      cancelButtonText: "暂时放弃"
    }).then(() => {
      utils.request({
        url:'/s/userinfo/CardCash',
        data:{
          softid:2,
          money:self.data.pean * 100
        },
        loading:true,
        callback:function (result) {
          if(result.status === 'ok'){
            setTimeout(function () {
              utils.toPage('/pages/me/notify/index?type=3',false,true);
            },100);
          }else{
            setTimeout(function () {
              utils.toPage('/pages/me/notify/index?type=4&msg=' + result.msg,false,true);
            },100);
          }
        }
      });
    }).catch(() => {
    });
  }
});
